<template>
	<view class="page" :style="{height: $u.sys().windowHeight + 'px'}">
		<view class="container">
			<view class="logo">LOGO</view>
			<view class="form">
				<u-form :model="form" :rules="rules" ref="form">
					<u-form-item prop="phone">
						<u-input v-model="form.phone" type="number" :placeholder="$t('member.login.phone')"
							border="bottom"></u-input>
					</u-form-item>
					<u-form-item prop="pwd">
						<u-input v-if="!isShowPwd" v-model="form.pwd" type="password" :placeholder="$t('member.login.pwd')"
							border="bottom">
							<template slot="suffix">
								<u-icon name="eye-off" color="#B9BFCB" @click="showPwd"></u-icon>
							</template>
						</u-input>
						<u-input v-else v-model="form.pwd" type="text" :placeholder="$t('member.login.pwd')" border="bottom">
							<template slot="suffix">
								<u-icon name="eye-fill" color="#B9BFCB" @click="showPwd"></u-icon>
							</template>
						</u-input>
					</u-form-item>
					<u-form-item prop="code">
						<u-input v-model="form.code" type="number" :placeholder="$t('member.register.code')" border="bottom">
							<template slot="suffix">
								<msg-code :phone="form.phone"></msg-code>
							</template>
						</u-input>
					</u-form-item>
					<u-form-item prop="company">
						<my-picker v-model="form.company" :option="companys" :placeholder="$t('member.register.company')"></my-picker>
					</u-form-item>
				</u-form>
			</view>
			<view class="submit">
				<u-button :loading="loading" class="btn" :text="$t('member.register.submit')" @click="submit"></u-button>
			</view>
			<view class="clause">
				<u-checkbox-group>
					<u-checkbox v-model="form.agent" size="32" active-color="#033787" shape="circle"></u-checkbox>
					{{$t('member.register.read-clause')}}
					<text class="text" @click="goClause">{{$t('member.register.clause')}}</text>
				</u-checkbox-group>
			</view>
		</view>
	</view>
</template>
<script>
	import picker from '@/components/picker.vue'
	import msgCode from '@/components/msg-code.vue'
	export default {
		components: {
			'my-picker': picker,
			msgCode
		},
		data() {
			return {
				form: {
					phone: '',
					pwd: '',
					code: '',
					company: '',
					agent: 0
				},
				rules: {
					phone: {
						type: 'number',
						required: true,
						message: this.$t('member.login.phone')
					},
					pwd: {
						type: 'string',
						required: true,
						message: this.$t('member.login.pwd')
					},
					code: {
						type: 'number',
						required: true,
						message: this.$t('member.register.code')
					},
					company: {
						type: 'number',
						required: true,
						message: this.$t('member.register.company')
					},
				},
				companys: [
					{id: 1, label: '单位1'},
					{id: 2, label: '单位2'},
					{id: 2, label: '单位3'},
					{id: 2, label: '单位4'},
					{id: 2, label: '单位5'},
					{id: 2, label: '单位6'},
					{id: 2, label: '单位7'},
					{id: 3, label: '单位8'}
				],
				isShowPwd: false,
				loading: false,
				waitCodeing: false,
				waitCodeSeconds: 60
			}
		},
		methods: {
			showPwd() {
				this.isShowPwd = !this.isShowPwd
			},
			submit() {
				this.$refs.form.validate().then(res => {
					this.loading = true
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index'
						})
					}, 1000)
				})
			},
			sendCode() {
				if (this.waitCodeing) {
					return
				}
				this.waitCodeing = true
				const interval = setInterval(() => {
					if (--this.waitCodeSeconds == 0) {
						clearInterval(interval)
						this.waitCodeing = false
						this.waitCodeSeconds = 60
					}
				}, 1000)
			},
			goClause() {
				uni.navigateTo({
					url: '/pages/content/clause'
				})
			}
		}
	}
</script>
<style lang="scss">
	.page {
		background-color: #F5F5E8;
	}

	.container {
		width: calc(100% - 112rpx);
		margin: 0 24rpx;
		border-radius: 32rpx;
		background-color: #fff;
		padding: 32rpx;
		display: inline-flex;
		margin-top: 236rpx;
		flex-flow: column;
		align-items: center;

		.logo {
			display: flex;
			justify-content: center;
			width: 160rpx;
			height: 160rpx;
			border-radius: 32rpx;
			background-color: #033787;
			position: relative;
			top: -112rpx;
			color: #fff;
			font-size: 40rpx;
			align-items: center;
		}

		.form {
			width: 100%;
			margin-top: -80rpx;
			font-size: 28rpx;
		}

		.submit {
			margin-top: 72rpx;
			width: 100%;
			font-weight: 600;

			.btn {
				color: #ffffff;
				height: 96rpx;
				border-radius: 48rpx;
				background-color: #033787;
				border: none;
			}
		}

		.clause {
			width: 100%;
			margin-top: 43rpx;
			font-size: 26rpx;
			text-align: left;
			color: #0C1626;
			display: flex;

			.text {
				color: #033787;
			}
		}
	}
</style>